using System;
using System.Collections.Generic;
using System.Text;
using Entities;

namespace BUS
{
    public class GioHangBUS
    {
        public List<GioHangDTO> itemcolection = new List<GioHangDTO>();
        public void Add(GioHangDTO item)
        {
            for (int i = 0; i < itemcolection.Count; i++)
            {
                if (item.MaMH == itemcolection[i].MaMH)
                {
                    itemcolection[i].SoLuong += item.SoLuong;
                    return;
                }
            }
            itemcolection.Add(item);
        }

        public void delete(GioHangDTO item)
        {
            for (int i = 0; i < itemcolection.Count; i++)
            {
                if (item.MaMH == itemcolection[i].MaMH)
                {
                    itemcolection.RemoveAt(i);
                    return;
                }
            }
        }
        public void update(GioHangDTO item)
        {
            for (int i = 0; i < itemcolection.Count; i++)
            {
                if (item.MaMH == itemcolection[i].MaMH)
                {
                    itemcolection[i].SoLuong = item.SoLuong;
                    return;
                }
            }
        }
        public double tongtien()
        {
            double t = 0;
            for (int i = 0; i < itemcolection.Count; i++)
            {
                t += itemcolection[i].Gia;

            }
            return t;
        }

    }
}
